/**
 * @properties={typeid:24,uuid:"58E7C573-F598-43D6-97EF-B4DEAEB5D62D"}
 * @AllowToRunInFind
 */
function gParamsApp() {
	/**@type {JSFoundSet<db:/fwk_navigation_infocom/param_app>} */
	var $params = databaseManager.getFoundSet('fwk_navigation_infocom','param_app')
	
	$params.find()
	$params.solucion = application.getSolutionName()
	if ($params.search() == 0)
		return 0
	
	var $cant = databaseManager.getFoundSetCount($params)
	if ($cant > 0)
	{
		for (var i = 1 ; i <= $cant ; i++)
		{
			var $rcd = $params.getRecord(i)
			var $valor
			switch( $rcd.tipo )
			{
				case 1:
				{
					$valor = $rcd.valor_txt
					break;
				}
				case 2:
				{
					$valor = $rcd.valor_int
					break;
				}
				case 3:
				{
					$valor = $rcd.valor_num
					break;
				}
			}
			globals[$rcd.nombre_var] = $valor
		}
	}
	return 1
}

/**
 * @param {Number} userv
 * @param {Number} usuario
 * 
 * @properties={typeid:24,uuid:"340A7B8B-F859-4DBB-A554-187AB97A7820"}
 * @AllowToRunInFind
 */
function gParamsUsr(userv, usuario)
{
	var $solucion		= application.getSolutionName()
	var $campos 		= ' nombre_var, tipo, valor_int, valor_txt, valor_num '
	var $where_usr		= ' usuario_id = ? AND solucion = ? '
	
	var $sql_usuario 	= 'SELECT' + $campos + 
							'FROM param_usuario '+
							'WHERE'+$where_usr
	
	var $sql_userv		= 'SELECT' + $campos + 
							'FROM param_usr '+
							'WHERE '+
							'userv_id = ? AND '+
							'solucion = ? AND '+
							'nombre_var NOT IN (SELECT nombre_var FROM param_usuario WHERE '+$where_usr+')'
	var $sql 			= $sql_usuario + ' UNION ' + $sql_userv
	var $args 			= [usuario, $solucion, userv, $solucion, usuario, $solucion]
	var $ds 			= databaseManager.getDataSetByQuery('fwk_navigation_infocom',$sql,$args,-1)
	var $cant 			= $ds.getMaxRowIndex()
	
	for (var i = 1 ; i <= $cant ; i++)
	{
		var $valor
		switch( $ds.getValue(i,2) )
		{
			case 1:
			{
				$valor = $ds.getValue(i,4)
				break;
			}
			case 2:
			{
				$valor = $ds.getValue(i,3)
				break;
			}
			case 3:
			{
				$valor = $ds.getValue(i,5)
				break;
			}
		}
		globals[$ds.getValue(i,1)] = $valor
	}
	
/*	var $params = databaseManager.getFoundSet('fwk_navigation_infocom','param_usr')
	
	$params.find()
	$params.solucion = application.getSolutionName()
	$params.userv_id = userv
	if ($params.search() == 0)
		return 0
	
	var $cant = databaseManager.getFoundSetCount($params)
	if ($cant > 0)
	{
		for (var i = 1 ; i <= $cant ; i++)
		{
			/** @type {JSRecord<db:/fwk_navigation_infocom/param_usr>}*/
/*			var $rcd = $params.getRecord(i)
			var $valor
			switch( $rcd.tipo )
			{
				case 1:
				{
					$valor = $rcd.valor_txt
					break;
				}
				case 2:
				{
					$valor = $rcd.valor_int
					break;
				}
				case 3:
				{
					$valor = $rcd.valor_num
					break;
				}
			}
			globals[$rcd.nombre_var] = $valor
		}
	}*/
	return 1
}

/**
 * @param {Number} userv
 * @param {Number} usuario
 * @properties={typeid:24,uuid:"CCB3B033-1403-4F96-A6E6-FD777484B637"}
 */
function gParamsAmbos(userv, usuario) {
	gParamsApp()
	if (userv && usuario)
		gParamsUsr(userv,usuario)
}
